function E = compute_Marr( P )

X=P;
x=double(X);
[C,L]=size(x);

%手动计算出来的7×7的高度对称高斯滤波模板，主要用于canny算子的计算
div = 12.2791;
G = [    0.0111    0.0388    0.0821    0.1054    0.0821    0.0388    0.0111;
    0.0388    0.1353    0.2865    0.3679    0.2865    0.1353    0.0388;
    0.0821    0.2865    0.6065    0.7788    0.6065    0.2865    0.0821;
    0.1054    0.3679    0.7788    1.0000    0.7788    0.3679    0.1054;
    0.0821    0.2865    0.6065    0.7788    0.6065    0.2865    0.0821;
    0.0388    0.1353    0.2865    0.3679    0.2865    0.1353    0.0388;
    0.0111    0.0388    0.0821    0.1054    0.0821    0.0388    0.0111];

%必要的变量声明
out = zeros(C,L);

factor = 16;
limit = 4;

temp = ones(C, L);
%%%%%%%%%%%%%%%
%%高斯滤波在本次实验中不是必要的，因为二阶求导模板已经包含高斯滤波成分。
for I = 4:C-3
    for J = 4:L-3
        result = 0;
        for u = -3:3
            for v = -3:3
                result = result + x(I+u, J+v)*G(u+4,v+4);
            end
        end
        x(I,J) = result/div;
    end
end
%%%%%%%%%%%%%%%%
%利用拉普拉斯高斯模板进行二阶求导
for I = 3:C-2
    for J = 3:L-2
        result = 16*x(I,J)-(x(I,J+1)+x(I,J-1)+x(I-1, J)+x(I+1, J))*2 ...
            -x(I,J-2)-x(I,J+2)-x(I-1, J-1)-x(I-1, J+1)-x(I-2, J)...
            -x(I+1,J-1)-x(I+1,J+1)-x(I-2, J);
        temp(I,J) = round(result/(factor*limit));
    end
end
%过零点检测，取边缘点
for I = 3:C-2
    for J = 3:L-2
        if temp(I, J-1)*temp(I, J+1) < 0 ||...
                temp(I-1, J)*temp(I+1, J) < 0  ||...
                temp(I-1, J-1)*temp(I+1, J+1) < 0 ||...
                temp(I-1, J+1)*temp(I+1, J-1) < 0
            out(I, J) = 256;
        end
    end
end
%%%%%%%%%%%%%%%%

E = uint8(out)-1;
end